package com.zjff.show.zjffshow.controller;

import com.zjff.show.zjffshow.entity.OutletsDao;
import com.zjff.show.zjffshow.entity.ResultDao;
import com.zjff.show.zjffshow.service.OutletsService;
import com.zjff.show.zjffshow.tool.JSONTool;
import com.zjff.show.zjffshow.tool.RedisTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import redis.clients.jedis.Jedis;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/map/")
public class OutletsController {
    @Autowired
    OutletsService outletsService;
    ResultDao resultDao = null;
    Jedis jedis = new RedisTool().getJedis();

    @GetMapping("/OutletsList")
    private String getOutletsList(@RequestParam("Long") String Long,
                                  @RequestParam("Lat") String Lat){
        resultDao = new ResultDao();
        boolean flag = false;
        if(Long == null || Long.equals("")){
            flag = true;
            resultDao.setMsg("没有获取最小范围的经度");
        }
        if(Lat == null || Lat.equals("")){
            flag = true;
            resultDao.setMsg("没有获取最小范围的纬度");
        }
        if (flag){
            resultDao.setCode("1");
        }else{
            double doubleLong = Double.parseDouble(Long);
            double doubleLat = Double.parseDouble(Lat);
            double SmallLong = doubleLong - 0.028;
            double BigLong = doubleLong + 0.028;
            double SmallLat = doubleLat - 0.028;
            double BigLat = doubleLat + 0.028;
            List<OutletsDao> list = outletsService.getOutletsList(SmallLong,BigLong,SmallLat,BigLat);
            resultDao.setCode("0");
            resultDao.setMsg("获取成功");
            resultDao.setData(list);
        }
        return JSONTool.getJsonTool().toJson(resultDao);
    }
}
